This procedure consists of two parts:
To create and prepare a Kanzi Studio project for dynamically loading texture images from the file system:






To create the C application for dynamically loading texture images from the file system:
projectLoaded function before kzApplicationConfigure and include the headers for the functions used by the projectLoaded function.#include <user/ui/kzu_screen.h>
#include <user/scene_graph/kzu_object.h>
#include <user/properties/kzu_fixed_properties.h>
KZ_CALLBACK kzsError projectLoaded(struct KzaApplication* application)
{
kzsError result;
/* Get the screen node of the application. */
struct KzuObjectNode* screenNode = kzuScreenToObjectNode(kzaApplicationGetScreen(application));
/* Use the alias to get the object node with an alias. */
/* Use the same alias name as you use in your Kanzi Studio project. */
struct KzuObjectNode* boxNode = kzuObjectNodeGetRelative(screenNode, "#BoxAlias");
/* Add the texture resource ID. */
/* Use the same file name of the texture image as you use on your file system. */
result = kzuObjectNodeAddResource(boxNode, "TextureFromFileSystem", "load_image:///TextureFromFileSystem.png");
kzsErrorForward(result);
/* Set the texture to the boxNode. */
result = kzuObjectNodeSetResourceIDProperty(boxNode, KZU_PROPERTY_TYPE_TEXTURE, "TextureFromFileSystem");
kzsErrorForward(result);
kzsSuccess();
}kzApplicationConfigure when Kanzi loads your application kzb binary files.configuration->onProjectLoaded = projectLoaded;
imageFileLoader and startup before kzApplicationConfigure and include the headers used by the functions:imageFileLoader loads an image from the file system and creates a texture from the image.startup registers a protocol handler that the resource manager uses to load images from the file system.#include <core/memory/kzc_memory_manager.h>
#include <core/util/image/kzc_image.h>
#include <user/resource/kzu_image_texture.h>
#include <user/resource/kzu_texture.h>
#include <user/ui/kzu_ui_domain.h>
#include <user/resource/kzu_resource_manager.h>
/* Resource manager protocol handler that is used with "load_image" protocol and which loads an image */
/* identified by the path from the file system and creates a texture from it. */
KZ_CALLBACK static kzsError imageFileLoader(struct KzuResourceManager* resourceManager, kzString resourceURL,
kzString protocol, kzString hostname, kzUint port, kzString path,
void* userData, struct KzuResource** out_resource)
{
kzsError result;
/* Get the memory manager of the resource manager. */
struct KzcMemoryManager* memoryManager = kzcMemoryGetManager(resourceManager);
struct KzcImage* image;
struct KzuImageTexture* texture;
/* Load vertically flipped image (for OpenGL). */
result = kzcImageLoadResourceFlipped(memoryManager, path, &image);
kzsErrorForward(result);
/* Create a texture from the loaded image. */
result = kzuImageTextureCreateFromImage(resourceManager, "Texture from the file system",
image, KZU_TEXTURE_FILTER_BILINEAR, KZU_TEXTURE_WRAP_REPEAT, 0.0f, &texture);
kzsErrorForward(result);
*out_resource = kzuImageTextureToResource(texture);
kzsSuccess();
}
KZ_CALLBACK kzsError startup(struct KzaApplication* application)
{
kzsError result;
/* Get the resource manager. */
struct KzuResourceManager* resourceManager = kzuUIDomainGetResourceManager(kzaApplicationGetUIDomain(application));
/* Register a protocol handler that the resource manager uses to load */
/* images from the file system. */
result = kzuResourceManagerRegisterProtocolHandler(resourceManager, "load_image", imageFileLoader, KZ_NULL);
kzsErrorForward(result);
kzsSuccess();
}kzApplicationConfigure when the application is launched.configuration->onStartup = startup;

projectLoaded function.